package com.hwua.view;

import com.hwua.entity.Score;
import com.hwua.entity.Teacher;
import com.hwua.service.ScoreService;
import com.hwua.service.TeacherService;
import com.hwua.service.impl.ScoreServiceImpl;
import com.hwua.service.impl.TeacherServiceImpl;
import com.hwua.tqm.FatherTable;

import java.util.List;
import java.util.Map;

/**
 * @author CQY
 */
public class ScoreView extends FatherTable{
    @Override
    public String[] columnNamesInit() {
        String[] s={"成绩编号","学号","姓名","成绩","课程编号","课程名称","教师姓名"};
        return s;
    }

    @Override
    public Object[][] tableDataInit() {
        ScoreService service=new ScoreServiceImpl();
        List<Map<Object,String>> list=service.findCorrelation();
        int row=list.size();
        Object[][] date=new Object[row][7];
        for (int i = 0; i <date.length ; i++) {
            Map map=list.get(i);
            date[i][0]=map.get(1);
            date[i][1]=map.get(2);
            date[i][2]=map.get(3);
            date[i][3]=map.get(4);
            date[i][4]=map.get(5);
            date[i][5]=map.get(6);
            date[i][6]=map.get(7);
        }
        return date;
    }

    @Override
    public void deleteMoreAction(Object[] ids) {
        ScoreService service=new ScoreServiceImpl();
        for (int i = 0; i <ids.length ; i++) {
            service.delete((int) ids[i]);
        }


    }

    @Override
    public void addSaveAction(Object[] obj) {

        ScoreService service=new ScoreServiceImpl();

        int id=Integer.parseInt(obj[0].toString());
        String stuid=(String)obj[1];
        String name=(String)obj[2];
        float sc=(float)obj[3];
        String courseid=(String)obj[4];
        String coursename=(String)obj[5];
        String teaname=(String)obj[6];
        Score score=new Score(id,stuid,courseid,sc);
        int row=service.save(score);
    }

    @Override
    public void updateSaveAction(Object[] obj) {
        ScoreService service=new ScoreServiceImpl();
        Score score=new Score();
        int id=(int) obj[0];
        String stuid=(String)obj[1];
        String name=(String)obj[2];
        float sc=(float)obj[3];
        String coursid=(String)obj[4];
        String coursename=(String)obj[5];
        String teaname=(String)obj[6];

        int row=service.update(score);

    }

    @Override
    public Object[][] searchAction(String keyword) {
        return new Object[0][];
    }

    @Override
    public void deleteAction(Object id) {
        ScoreService service=new ScoreServiceImpl();
        service.delete((int)id);

    }
}
